<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>yadis.discover</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="yadis-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://www.openidenabled.com/yadis/">Python-Yadis</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="yadis-module.html">Package&nbsp;yadis</a> ::
        Module&nbsp;discover
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="yadis.discover-pysrc.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<h1 class="epydoc">Source Code for <a href="yadis.discover-module.html">Module yadis.discover</a></h1>
<pre class="py-src">
<tt class="py-lineno">  1</tt>  <tt class="py-line"><tt class="py-comment"># -*- test-case-name: yadis.test.test_discover -*-</tt> </tt>
<tt class="py-lineno">  2</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-name">__all__</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-string">'discover'</tt><tt class="py-op">,</tt> <tt class="py-string">'DiscoveryResult'</tt><tt class="py-op">,</tt> <tt class="py-string">'DiscoveryFailure'</tt><tt class="py-op">]</tt> </tt>
<tt class="py-lineno">  3</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno">  4</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">cStringIO</tt> <tt class="py-keyword">import</tt> <tt class="py-name">StringIO</tt> </tt>
<tt class="py-lineno">  5</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno">  6</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">urljr</tt> <tt class="py-keyword">import</tt> <tt class="py-name">fetchers</tt> </tt>
<tt class="py-lineno">  7</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno">  8</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-0" class="py-name" targets="Package yadis=yadis-module.html"><a title="yadis" class="py-name" href="#" onclick="return doclink('link-0', 'yadis', 'link-0');">yadis</a></tt></tt><tt class="py-op">.</tt><tt id="link-1" class="py-name" targets="Module yadis.constants=yadis.constants-module.html"><a title="yadis.constants" class="py-name" href="#" onclick="return doclink('link-1', 'constants', 'link-1');">constants</a></tt></tt> <tt class="py-keyword">import</tt> \ </tt>
<tt class="py-lineno">  9</tt>  <tt class="py-line">     <tt id="link-2" class="py-name" targets="Variable yadis.constants.YADIS_HEADER_NAME=yadis.constants-module.html#YADIS_HEADER_NAME"><a title="yadis.constants.YADIS_HEADER_NAME" class="py-name" href="#" onclick="return doclink('link-2', 'YADIS_HEADER_NAME', 'link-2');">YADIS_HEADER_NAME</a></tt></tt><tt class="py-op">,</tt> <tt id="link-3" class="py-name" targets="Variable yadis.constants.YADIS_CONTENT_TYPE=yadis.constants-module.html#YADIS_CONTENT_TYPE"><a title="yadis.constants.YADIS_CONTENT_TYPE" class="py-name" href="#" onclick="return doclink('link-3', 'YADIS_CONTENT_TYPE', 'link-3');">YADIS_CONTENT_TYPE</a></tt></tt><tt class="py-op">,</tt> <tt id="link-4" class="py-name" targets="Variable yadis.constants.YADIS_ACCEPT_HEADER=yadis.constants-module.html#YADIS_ACCEPT_HEADER"><a title="yadis.constants.YADIS_ACCEPT_HEADER" class="py-name" href="#" onclick="return doclink('link-4', 'YADIS_ACCEPT_HEADER', 'link-4');">YADIS_ACCEPT_HEADER</a></tt></tt> </tt>
<tt class="py-lineno"> 10</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-5" class="py-name"><a title="yadis" class="py-name" href="#" onclick="return doclink('link-5', 'yadis', 'link-0');">yadis</a></tt></tt><tt class="py-op">.</tt><tt id="link-6" class="py-name" targets="Module yadis.parsehtml=yadis.parsehtml-module.html"><a title="yadis.parsehtml" class="py-name" href="#" onclick="return doclink('link-6', 'parsehtml', 'link-6');">parsehtml</a></tt></tt> <tt class="py-keyword">import</tt> <tt id="link-7" class="py-name" targets="Class yadis.parsehtml.MetaNotFound=yadis.parsehtml.MetaNotFound-class.html"><a title="yadis.parsehtml.MetaNotFound" class="py-name" href="#" onclick="return doclink('link-7', 'MetaNotFound', 'link-7');">MetaNotFound</a></tt></tt><tt class="py-op">,</tt> <tt id="link-8" class="py-name" targets="Function yadis.parsehtml.findHTMLMeta()=yadis.parsehtml-module.html#findHTMLMeta"><a title="yadis.parsehtml.findHTMLMeta" class="py-name" href="#" onclick="return doclink('link-8', 'findHTMLMeta', 'link-8');">findHTMLMeta</a></tt></tt> </tt>
<tt class="py-lineno"> 11</tt>  <tt class="py-line"> </tt>
<a name="DiscoveryFailure"></a><div id="DiscoveryFailure-def"><tt class="py-lineno"> 12</tt> <a class="py-toggle" href="#" id="DiscoveryFailure-toggle" onclick="return toggle('DiscoveryFailure');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="yadis.discover.DiscoveryFailure-class.html">DiscoveryFailure</a><tt class="py-op">(</tt><tt class="py-base-class">Exception</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="DiscoveryFailure-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="DiscoveryFailure-expanded"><tt class="py-lineno"> 13</tt>  <tt class="py-line">    <tt class="py-docstring">"""Raised when a YADIS protocol error occurs in the discovery process"""</tt> </tt>
<tt class="py-lineno"> 14</tt>  <tt class="py-line">    <tt id="link-9" class="py-name" targets="Variable yadis.discover.DiscoveryFailure.identity_url=yadis.discover.DiscoveryFailure-class.html#identity_url"><a title="yadis.discover.DiscoveryFailure.identity_url" class="py-name" href="#" onclick="return doclink('link-9', 'identity_url', 'link-9');">identity_url</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt> </tt>
<tt class="py-lineno"> 15</tt>  <tt class="py-line"> </tt>
<a name="DiscoveryFailure.__init__"></a><div id="DiscoveryFailure.__init__-def"><tt class="py-lineno"> 16</tt> <a class="py-toggle" href="#" id="DiscoveryFailure.__init__-toggle" onclick="return toggle('DiscoveryFailure.__init__');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="yadis.discover.DiscoveryFailure-class.html#__init__">__init__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">message</tt><tt class="py-op">,</tt> <tt class="py-param">http_response</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="DiscoveryFailure.__init__-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="DiscoveryFailure.__init__-expanded"><tt class="py-lineno"> 17</tt>  <tt class="py-line">        <tt class="py-name">Exception</tt><tt class="py-op">.</tt><tt id="link-10" class="py-name" targets="Method yadis.discover.DiscoveryFailure.__init__()=yadis.discover.DiscoveryFailure-class.html#__init__,Method yadis.discover.DiscoveryResult.__init__()=yadis.discover.DiscoveryResult-class.html#__init__,Method yadis.filters.BasicServiceEndpoint.__init__()=yadis.filters.BasicServiceEndpoint-class.html#__init__,Method yadis.filters.CompoundFilter.__init__()=yadis.filters.CompoundFilter-class.html#__init__,Method yadis.filters.TransformFilterMaker.__init__()=yadis.filters.TransformFilterMaker-class.html#__init__,Method yadis.manager.Discovery.__init__()=yadis.manager.Discovery-class.html#__init__,Method yadis.manager.YadisServiceManager.__init__()=yadis.manager.YadisServiceManager-class.html#__init__,Method yadis.parsehtml.YadisHTMLParser.__init__()=yadis.parsehtml.YadisHTMLParser-class.html#__init__,Method yadis.test.livediscover.DiscoverTestCase.__init__()=yadis.test.livediscover.DiscoverTestCase-class.html#__init__,Method yadis.test.test_accept.MatchAcceptTest.__init__()=yadis.test.test_accept.MatchAcceptTest-class.html#__init__,Method yadis.test.test_discover.TestFetcher.__init__()=yadis.test.test_discover.TestFetcher-class.html#__init__,Method yadis.test.test_discover.TestSecondGet.MockFetcher.__init__()=yadis.test.test_discover.TestSecondGet.MockFetcher-class.html#__init__,Method yadis.test.test_discover._TestCase.__init__()=yadis.test.test_discover._TestCase-class.html#__init__,Method yadis.test.test_parsehtml._TestCase.__init__()=yadis.test.test_parsehtml._TestCase-class.html#__init__,Method yadis.xrires.ProxyResolver.__init__()=yadis.xrires.ProxyResolver-class.html#__init__"><a title="yadis.discover.DiscoveryFailure.__init__
yadis.discover.DiscoveryResult.__init__
yadis.filters.BasicServiceEndpoint.__init__
yadis.filters.CompoundFilter.__init__
yadis.filters.TransformFilterMaker.__init__
yadis.manager.Discovery.__init__
yadis.manager.YadisServiceManager.__init__
yadis.parsehtml.YadisHTMLParser.__init__
yadis.test.livediscover.DiscoverTestCase.__init__
yadis.test.test_accept.MatchAcceptTest.__init__
yadis.test.test_discover.TestFetcher.__init__
yadis.test.test_discover.TestSecondGet.MockFetcher.__init__
yadis.test.test_discover._TestCase.__init__
yadis.test.test_parsehtml._TestCase.__init__
yadis.xrires.ProxyResolver.__init__" class="py-name" href="#" onclick="return doclink('link-10', '__init__', 'link-10');">__init__</a></tt></tt><tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">,</tt> <tt class="py-name">message</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno"> 18</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">http_response</tt> <tt class="py-op">=</tt> <tt class="py-name">http_response</tt> </tt>
</div></div><tt class="py-lineno"> 19</tt>  <tt class="py-line"> </tt>
<a name="DiscoveryResult"></a><div id="DiscoveryResult-def"><tt class="py-lineno"> 20</tt> <a class="py-toggle" href="#" id="DiscoveryResult-toggle" onclick="return toggle('DiscoveryResult');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="yadis.discover.DiscoveryResult-class.html">DiscoveryResult</a><tt class="py-op">(</tt><tt class="py-base-class">object</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="DiscoveryResult-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="DiscoveryResult-expanded"><tt class="py-lineno"> 21</tt>  <tt class="py-line">    <tt class="py-docstring">"""Contains the result of performing Yadis discovery on a URI"""</tt> </tt>
<tt class="py-lineno"> 22</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 23</tt>  <tt class="py-line">    <tt class="py-comment"># The URI that was passed to the fetcher</tt> </tt>
<tt class="py-lineno"> 24</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt id="link-11" class="py-name" targets="Variable yadis.discover.DiscoveryResult.request_uri=yadis.discover.DiscoveryResult-class.html#request_uri"><a title="yadis.discover.DiscoveryResult.request_uri" class="py-name" href="#" onclick="return doclink('link-11', 'request_uri', 'link-11');">request_uri</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt> </tt>
<tt class="py-lineno"> 25</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 26</tt>  <tt class="py-line">    <tt class="py-comment"># The result of following redirects from the request_uri</tt> </tt>
<tt class="py-lineno"> 27</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt id="link-12" class="py-name" targets="Variable yadis.discover.DiscoveryResult.normalized_uri=yadis.discover.DiscoveryResult-class.html#normalized_uri"><a title="yadis.discover.DiscoveryResult.normalized_uri" class="py-name" href="#" onclick="return doclink('link-12', 'normalized_uri', 'link-12');">normalized_uri</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt> </tt>
<tt class="py-lineno"> 28</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 29</tt>  <tt class="py-line">    <tt class="py-comment"># The URI from which the response text was returned (set to</tt> </tt>
<tt class="py-lineno"> 30</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt class="py-comment"># None if there was no XRDS document found)</tt> </tt>
<tt class="py-lineno"> 31</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt id="link-13" class="py-name" targets="Variable yadis.discover.DiscoveryResult.xrds_uri=yadis.discover.DiscoveryResult-class.html#xrds_uri"><a title="yadis.discover.DiscoveryResult.xrds_uri" class="py-name" href="#" onclick="return doclink('link-13', 'xrds_uri', 'link-13');">xrds_uri</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt> </tt>
<tt class="py-lineno"> 32</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 33</tt>  <tt class="py-line">    <tt class="py-comment"># The content-type returned with the response_text</tt> </tt>
<tt class="py-lineno"> 34</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt id="link-14" class="py-name" targets="Variable yadis.discover.DiscoveryResult.content_type=yadis.discover.DiscoveryResult-class.html#content_type"><a title="yadis.discover.DiscoveryResult.content_type" class="py-name" href="#" onclick="return doclink('link-14', 'content_type', 'link-14');">content_type</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt> </tt>
<tt class="py-lineno"> 35</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 36</tt>  <tt class="py-line">    <tt class="py-comment"># The document returned from the xrds_uri</tt> </tt>
<tt class="py-lineno"> 37</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt id="link-15" class="py-name" targets="Variable yadis.discover.DiscoveryResult.response_text=yadis.discover.DiscoveryResult-class.html#response_text"><a title="yadis.discover.DiscoveryResult.response_text" class="py-name" href="#" onclick="return doclink('link-15', 'response_text', 'link-15');">response_text</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt> </tt>
<tt class="py-lineno"> 38</tt>  <tt class="py-line"> </tt>
<a name="DiscoveryResult.__init__"></a><div id="DiscoveryResult.__init__-def"><tt class="py-lineno"> 39</tt> <a class="py-toggle" href="#" id="DiscoveryResult.__init__-toggle" onclick="return toggle('DiscoveryResult.__init__');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="yadis.discover.DiscoveryResult-class.html#__init__">__init__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">request_uri</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="DiscoveryResult.__init__-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="DiscoveryResult.__init__-expanded"><tt class="py-lineno"> 40</tt>  <tt class="py-line">        <tt class="py-docstring">"""Initialize the state of the object</tt> </tt>
<tt class="py-lineno"> 41</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<tt class="py-lineno"> 42</tt>  <tt class="py-line"><tt class="py-docstring">        sets all attributes to None except the request_uri</tt> </tt>
<tt class="py-lineno"> 43</tt>  <tt class="py-line"><tt class="py-docstring">        """</tt> </tt>
<tt class="py-lineno"> 44</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-16" class="py-name"><a title="yadis.discover.DiscoveryResult.request_uri" class="py-name" href="#" onclick="return doclink('link-16', 'request_uri', 'link-11');">request_uri</a></tt></tt> <tt class="py-op">=</tt> <tt id="link-17" class="py-name"><a title="yadis.discover.DiscoveryResult.request_uri" class="py-name" href="#" onclick="return doclink('link-17', 'request_uri', 'link-11');">request_uri</a></tt></tt> </tt>
</div><tt class="py-lineno"> 45</tt>  <tt class="py-line"> </tt>
<a name="DiscoveryResult.usedYadisLocation"></a><div id="DiscoveryResult.usedYadisLocation-def"><tt class="py-lineno"> 46</tt> <a class="py-toggle" href="#" id="DiscoveryResult.usedYadisLocation-toggle" onclick="return toggle('DiscoveryResult.usedYadisLocation');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="yadis.discover.DiscoveryResult-class.html#usedYadisLocation">usedYadisLocation</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="DiscoveryResult.usedYadisLocation-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="DiscoveryResult.usedYadisLocation-expanded"><tt class="py-lineno"> 47</tt>  <tt class="py-line">        <tt class="py-docstring">"""Was the Yadis protocol's indirection used?"""</tt> </tt>
<tt class="py-lineno"> 48</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-18" class="py-name"><a title="yadis.discover.DiscoveryResult.normalized_uri" class="py-name" href="#" onclick="return doclink('link-18', 'normalized_uri', 'link-12');">normalized_uri</a></tt></tt> <tt class="py-op">==</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-19" class="py-name"><a title="yadis.discover.DiscoveryResult.xrds_uri" class="py-name" href="#" onclick="return doclink('link-19', 'xrds_uri', 'link-13');">xrds_uri</a></tt></tt> </tt>
</div><tt class="py-lineno"> 49</tt>  <tt class="py-line"> </tt>
<a name="DiscoveryResult.isXRDS"></a><div id="DiscoveryResult.isXRDS-def"><tt class="py-lineno"> 50</tt> <a class="py-toggle" href="#" id="DiscoveryResult.isXRDS-toggle" onclick="return toggle('DiscoveryResult.isXRDS');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="yadis.discover.DiscoveryResult-class.html#isXRDS">isXRDS</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="DiscoveryResult.isXRDS-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="DiscoveryResult.isXRDS-expanded"><tt class="py-lineno"> 51</tt>  <tt class="py-line">        <tt class="py-docstring">"""Is the response text supposed to be an XRDS document?"""</tt> </tt>
<tt class="py-lineno"> 52</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-20" class="py-name" targets="Method yadis.discover.DiscoveryResult.usedYadisLocation()=yadis.discover.DiscoveryResult-class.html#usedYadisLocation"><a title="yadis.discover.DiscoveryResult.usedYadisLocation" class="py-name" href="#" onclick="return doclink('link-20', 'usedYadisLocation', 'link-20');">usedYadisLocation</a></tt></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> <tt class="py-keyword">or</tt> </tt>
<tt class="py-lineno"> 53</tt>  <tt class="py-line">                <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-21" class="py-name"><a title="yadis.discover.DiscoveryResult.content_type" class="py-name" href="#" onclick="return doclink('link-21', 'content_type', 'link-14');">content_type</a></tt></tt> <tt class="py-op">==</tt> <tt id="link-22" class="py-name"><a title="yadis.constants.YADIS_CONTENT_TYPE" class="py-name" href="#" onclick="return doclink('link-22', 'YADIS_CONTENT_TYPE', 'link-3');">YADIS_CONTENT_TYPE</a></tt></tt><tt class="py-op">)</tt> </tt>
</div></div><tt class="py-lineno"> 54</tt>  <tt class="py-line"> </tt>
<a name="discover"></a><div id="discover-def"><tt class="py-lineno"> 55</tt> <a class="py-toggle" href="#" id="discover-toggle" onclick="return toggle('discover');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="yadis.discover-module.html#discover">discover</a><tt class="py-op">(</tt><tt class="py-param">uri</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="discover-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="discover-expanded"><tt class="py-lineno"> 56</tt>  <tt class="py-line">    <tt class="py-docstring">"""Discover services for a given URI.</tt> </tt>
<tt class="py-lineno"> 57</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<tt class="py-lineno"> 58</tt>  <tt class="py-line"><tt class="py-docstring">    @param uri: The identity URI as a well-formed http or https</tt> </tt>
<tt class="py-lineno"> 59</tt>  <tt class="py-line"><tt class="py-docstring">        URI. The well-formedness and the protocol are not checked, but</tt> </tt>
<tt class="py-lineno"> 60</tt>  <tt class="py-line"><tt class="py-docstring">        the results of this function are undefined if those properties</tt> </tt>
<tt class="py-lineno"> 61</tt>  <tt class="py-line"><tt class="py-docstring">        do not hold.</tt> </tt>
<tt class="py-lineno"> 62</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<tt class="py-lineno"> 63</tt>  <tt class="py-line"><tt class="py-docstring">    @return: DiscoveryResult object</tt> </tt>
<tt class="py-lineno"> 64</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<tt class="py-lineno"> 65</tt>  <tt class="py-line"><tt class="py-docstring">    @raises Exception: Any exception that can be raised by fetching a URL with</tt> </tt>
<tt class="py-lineno"> 66</tt>  <tt class="py-line"><tt class="py-docstring">        the given fetcher.</tt> </tt>
<tt class="py-lineno"> 67</tt>  <tt class="py-line"><tt class="py-docstring">    """</tt> </tt>
<tt class="py-lineno"> 68</tt>  <tt class="py-line">    <tt class="py-name">result</tt> <tt class="py-op">=</tt> <tt id="link-23" class="py-name" targets="Class yadis.discover.DiscoveryResult=yadis.discover.DiscoveryResult-class.html"><a title="yadis.discover.DiscoveryResult" class="py-name" href="#" onclick="return doclink('link-23', 'DiscoveryResult', 'link-23');">DiscoveryResult</a></tt></tt><tt class="py-op">(</tt><tt class="py-name">uri</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno"> 69</tt>  <tt class="py-line">    <tt class="py-name">resp</tt> <tt class="py-op">=</tt> <tt class="py-name">fetchers</tt><tt class="py-op">.</tt><tt id="link-24" class="py-name" targets="Method yadis.test.test_discover.TestFetcher.fetch()=yadis.test.test_discover.TestFetcher-class.html#fetch,Method yadis.test.test_discover.TestSecondGet.MockFetcher.fetch()=yadis.test.test_discover.TestSecondGet.MockFetcher-class.html#fetch"><a title="yadis.test.test_discover.TestFetcher.fetch
yadis.test.test_discover.TestSecondGet.MockFetcher.fetch" class="py-name" href="#" onclick="return doclink('link-24', 'fetch', 'link-24');">fetch</a></tt></tt><tt class="py-op">(</tt><tt class="py-name">uri</tt><tt class="py-op">,</tt> <tt class="py-name">headers</tt><tt class="py-op">=</tt><tt class="py-op">{</tt><tt class="py-string">'Accept'</tt><tt class="py-op">:</tt> <tt id="link-25" class="py-name"><a title="yadis.constants.YADIS_ACCEPT_HEADER" class="py-name" href="#" onclick="return doclink('link-25', 'YADIS_ACCEPT_HEADER', 'link-4');">YADIS_ACCEPT_HEADER</a></tt></tt><tt class="py-op">}</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno"> 70</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">status</tt> <tt class="py-op">!=</tt> <tt class="py-number">200</tt><tt class="py-op">:</tt> </tt>
<tt class="py-lineno"> 71</tt>  <tt class="py-line">        <tt class="py-keyword">raise</tt> <tt id="link-26" class="py-name" targets="Class yadis.discover.DiscoveryFailure=yadis.discover.DiscoveryFailure-class.html"><a title="yadis.discover.DiscoveryFailure" class="py-name" href="#" onclick="return doclink('link-26', 'DiscoveryFailure', 'link-26');">DiscoveryFailure</a></tt></tt><tt class="py-op">(</tt> </tt>
<tt class="py-lineno"> 72</tt>  <tt class="py-line">            <tt class="py-string">'HTTP Response status from identity URL host is not 200. '</tt> </tt>
<tt class="py-lineno"> 73</tt>  <tt class="py-line">            <tt class="py-string">'Got status %r'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">status</tt><tt class="py-op">,</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-name">resp</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno"> 74</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 75</tt>  <tt class="py-line">    <tt class="py-comment"># Note the URL after following redirects</tt> </tt>
<tt class="py-lineno"> 76</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-27" class="py-name"><a title="yadis.discover.DiscoveryResult.normalized_uri" class="py-name" href="#" onclick="return doclink('link-27', 'normalized_uri', 'link-12');">normalized_uri</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">final_url</tt> </tt>
<tt class="py-lineno"> 77</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 78</tt>  <tt class="py-line">    <tt class="py-comment"># Attempt to find out where to go to discover the document</tt> </tt>
<tt class="py-lineno"> 79</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt class="py-comment"># or if we already have it</tt> </tt>
<tt class="py-lineno"> 80</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-28" class="py-name"><a title="yadis.discover.DiscoveryResult.content_type" class="py-name" href="#" onclick="return doclink('link-28', 'content_type', 'link-14');">content_type</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">headers</tt><tt class="py-op">.</tt><tt class="py-name">get</tt><tt class="py-op">(</tt><tt class="py-string">'content-type'</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno"> 81</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 82</tt>  <tt class="py-line">    <tt class="py-comment"># According to the spec, the content-type header must be an exact</tt> </tt>
<tt class="py-lineno"> 83</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt class="py-comment"># match, or else we have to look for an indirection.</tt> </tt>
<tt class="py-lineno"> 84</tt>  <tt class="py-line"><tt class="py-comment"></tt>    <tt class="py-keyword">if</tt> <tt class="py-op">(</tt><tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-29" class="py-name"><a title="yadis.discover.DiscoveryResult.content_type" class="py-name" href="#" onclick="return doclink('link-29', 'content_type', 'link-14');">content_type</a></tt></tt> <tt class="py-keyword">and</tt> </tt>
<tt class="py-lineno"> 85</tt>  <tt class="py-line">        <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-30" class="py-name"><a title="yadis.discover.DiscoveryResult.content_type" class="py-name" href="#" onclick="return doclink('link-30', 'content_type', 'link-14');">content_type</a></tt></tt><tt class="py-op">.</tt><tt class="py-name">split</tt><tt class="py-op">(</tt><tt class="py-string">';'</tt><tt class="py-op">,</tt> <tt class="py-number">1</tt><tt class="py-op">)</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">.</tt><tt class="py-name">lower</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> <tt class="py-op">==</tt> <tt id="link-31" class="py-name"><a title="yadis.constants.YADIS_CONTENT_TYPE" class="py-name" href="#" onclick="return doclink('link-31', 'YADIS_CONTENT_TYPE', 'link-3');">YADIS_CONTENT_TYPE</a></tt></tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<tt class="py-lineno"> 86</tt>  <tt class="py-line">        <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-32" class="py-name"><a title="yadis.discover.DiscoveryResult.xrds_uri" class="py-name" href="#" onclick="return doclink('link-32', 'xrds_uri', 'link-13');">xrds_uri</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-33" class="py-name"><a title="yadis.discover.DiscoveryResult.normalized_uri" class="py-name" href="#" onclick="return doclink('link-33', 'normalized_uri', 'link-12');">normalized_uri</a></tt></tt> </tt>
<tt class="py-lineno"> 87</tt>  <tt class="py-line">    <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<tt class="py-lineno"> 88</tt>  <tt class="py-line">        <tt class="py-comment"># Try the header</tt> </tt>
<tt class="py-lineno"> 89</tt>  <tt class="py-line"><tt class="py-comment"></tt>        <tt class="py-name">yadis_loc</tt> <tt class="py-op">=</tt> <tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">headers</tt><tt class="py-op">.</tt><tt class="py-name">get</tt><tt class="py-op">(</tt><tt id="link-34" class="py-name"><a title="yadis.constants.YADIS_HEADER_NAME" class="py-name" href="#" onclick="return doclink('link-34', 'YADIS_HEADER_NAME', 'link-2');">YADIS_HEADER_NAME</a></tt></tt><tt class="py-op">.</tt><tt class="py-name">lower</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno"> 90</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno"> 91</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">yadis_loc</tt><tt class="py-op">:</tt> </tt>
<tt class="py-lineno"> 92</tt>  <tt class="py-line">            <tt class="py-comment"># Parse as HTML if the header is missing.</tt> </tt>
<tt class="py-lineno"> 93</tt>  <tt class="py-line"><tt class="py-comment"></tt>            <tt class="py-comment">#</tt> </tt>
<tt class="py-lineno"> 94</tt>  <tt class="py-line"><tt class="py-comment"></tt>            <tt class="py-comment"># XXX: do we want to do something with content-type, like</tt> </tt>
<tt class="py-lineno"> 95</tt>  <tt class="py-line"><tt class="py-comment"></tt>            <tt class="py-comment"># have a whitelist or a blacklist (for detecting that it's</tt> </tt>
<tt class="py-lineno"> 96</tt>  <tt class="py-line"><tt class="py-comment"></tt>            <tt class="py-comment"># HTML)?</tt> </tt>
<tt class="py-lineno"> 97</tt>  <tt class="py-line"><tt class="py-comment"></tt>            <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
<tt class="py-lineno"> 98</tt>  <tt class="py-line">                <tt class="py-name">yadis_loc</tt> <tt class="py-op">=</tt> <tt id="link-35" class="py-name"><a title="yadis.parsehtml.findHTMLMeta" class="py-name" href="#" onclick="return doclink('link-35', 'findHTMLMeta', 'link-8');">findHTMLMeta</a></tt></tt><tt class="py-op">(</tt><tt class="py-name">StringIO</tt><tt class="py-op">(</tt><tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">body</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno"> 99</tt>  <tt class="py-line">            <tt class="py-keyword">except</tt> <tt id="link-36" class="py-name"><a title="yadis.parsehtml.MetaNotFound" class="py-name" href="#" onclick="return doclink('link-36', 'MetaNotFound', 'link-7');">MetaNotFound</a></tt></tt><tt class="py-op">:</tt> </tt>
<tt class="py-lineno">100</tt>  <tt class="py-line">                <tt class="py-keyword">pass</tt> </tt>
<tt class="py-lineno">101</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno">102</tt>  <tt class="py-line">        <tt class="py-comment"># At this point, we have not found a YADIS Location URL. We</tt> </tt>
<tt class="py-lineno">103</tt>  <tt class="py-line"><tt class="py-comment"></tt>        <tt class="py-comment"># will return the content that we scanned so that the caller</tt> </tt>
<tt class="py-lineno">104</tt>  <tt class="py-line"><tt class="py-comment"></tt>        <tt class="py-comment"># can try to treat it as an XRDS if it wishes.</tt> </tt>
<tt class="py-lineno">105</tt>  <tt class="py-line"><tt class="py-comment"></tt>        <tt class="py-keyword">if</tt> <tt class="py-name">yadis_loc</tt><tt class="py-op">:</tt> </tt>
<tt class="py-lineno">106</tt>  <tt class="py-line">            <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-37" class="py-name"><a title="yadis.discover.DiscoveryResult.xrds_uri" class="py-name" href="#" onclick="return doclink('link-37', 'xrds_uri', 'link-13');">xrds_uri</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">yadis_loc</tt> </tt>
<tt class="py-lineno">107</tt>  <tt class="py-line">            <tt class="py-name">resp</tt> <tt class="py-op">=</tt> <tt class="py-name">fetchers</tt><tt class="py-op">.</tt><tt id="link-38" class="py-name"><a title="yadis.test.test_discover.TestFetcher.fetch
yadis.test.test_discover.TestSecondGet.MockFetcher.fetch" class="py-name" href="#" onclick="return doclink('link-38', 'fetch', 'link-24');">fetch</a></tt></tt><tt class="py-op">(</tt><tt class="py-name">yadis_loc</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno">108</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">status</tt> <tt class="py-op">!=</tt> <tt class="py-number">200</tt><tt class="py-op">:</tt> </tt>
<tt class="py-lineno">109</tt>  <tt class="py-line">                <tt class="py-name">exc</tt> <tt class="py-op">=</tt> <tt id="link-39" class="py-name"><a title="yadis.discover.DiscoveryFailure" class="py-name" href="#" onclick="return doclink('link-39', 'DiscoveryFailure', 'link-26');">DiscoveryFailure</a></tt></tt><tt class="py-op">(</tt> </tt>
<tt class="py-lineno">110</tt>  <tt class="py-line">                    <tt class="py-string">'HTTP Response status from Yadis host is not 200. '</tt> </tt>
<tt class="py-lineno">111</tt>  <tt class="py-line">                    <tt class="py-string">'Got status %r'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">status</tt><tt class="py-op">,</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-name">resp</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno">112</tt>  <tt class="py-line">                <tt class="py-name">exc</tt><tt class="py-op">.</tt><tt id="link-40" class="py-name"><a title="yadis.discover.DiscoveryFailure.identity_url" class="py-name" href="#" onclick="return doclink('link-40', 'identity_url', 'link-9');">identity_url</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-41" class="py-name"><a title="yadis.discover.DiscoveryResult.normalized_uri" class="py-name" href="#" onclick="return doclink('link-41', 'normalized_uri', 'link-12');">normalized_uri</a></tt></tt> </tt>
<tt class="py-lineno">113</tt>  <tt class="py-line">                <tt class="py-keyword">raise</tt> <tt class="py-name">exc</tt> </tt>
<tt class="py-lineno">114</tt>  <tt class="py-line">            <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-42" class="py-name"><a title="yadis.discover.DiscoveryResult.content_type" class="py-name" href="#" onclick="return doclink('link-42', 'content_type', 'link-14');">content_type</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">headers</tt><tt class="py-op">.</tt><tt class="py-name">get</tt><tt class="py-op">(</tt><tt class="py-string">'content-type'</tt><tt class="py-op">)</tt> </tt>
<tt class="py-lineno">115</tt>  <tt class="py-line"> </tt>
<tt class="py-lineno">116</tt>  <tt class="py-line">    <tt class="py-name">result</tt><tt class="py-op">.</tt><tt id="link-43" class="py-name"><a title="yadis.discover.DiscoveryResult.response_text" class="py-name" href="#" onclick="return doclink('link-43', 'response_text', 'link-15');">response_text</a></tt></tt> <tt class="py-op">=</tt> <tt class="py-name">resp</tt><tt class="py-op">.</tt><tt class="py-name">body</tt> </tt>
<tt class="py-lineno">117</tt>  <tt class="py-line">    <tt class="py-keyword">return</tt> <tt class="py-name">result</tt> </tt>
</div><tt class="py-lineno">118</tt>  <tt class="py-line"> </tt><script type="text/javascript">
<!--
expandto(location.href);
// -->
</script>
</pre>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="yadis-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://www.openidenabled.com/yadis/">Python-Yadis</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">Generated by Epydoc
        3.0alpha3 on Fri Dec  8 13:17:18 2006</td>
    <td align="right" class="footer">
      <a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie()
  // -->
</script>
  
</body>
</html>
